package com.lenovo.agricultureclient.ui.dialog;

import android.app.Activity;
import android.graphics.Color;

import com.lenovo.agricultureclient.ClientApp;
import com.lenovo.agricultureclient.R;
/**
 * 设置土壤温湿度阀值的对话框
 * @author zongbingwu
 *
 */
public class SettingSoilDialog extends SettingBaseDialog 
{
	public SettingSoilDialog(Activity act, ClientApp app) {
		super(act, app);
	}

	@Override
	protected void onInitView() {
		super.onInitView();
		mTitleTextView.setText(R.string.soil_threshold_value_setting);
		//初始化土壤温度相关控件
		mMajorValueTitleTV.setText(R.string.soil_tmper_current_value);
		mMajorStatusTitleTV.setText(R.string.soil_tmper_current_status);
		mMajorMinET.setText(mSensorConfig.minSoilTemperature+"");
		mMajorMaxET.setText(mSensorConfig.maxSoilTemperature+"");
		//初始化土壤湿度相关控件
		mSlaveValueTitleTV.setText(R.string.soil_humid_current_value);
		mSlaveStatusTitleTV.setText(R.string.soil_humid_current_status);
		mSlaveMinET.setText(mSensorConfig.minSoilHumidity+"");
		mSlaveMaxET.setText(mSensorConfig.maxSoilHumidity+"");
	}

	@Override
	protected void onUpateView() {
		super.onUpateView();
		//刷新土壤温度相关控件
		{
			int majorValue = mSensorValue.getSoilTemper();
			int majorMin = mSensorConfig.minSoilTemperature;
			int majorMax = mSensorConfig.maxSoilTemperature;
			mMajorValueTV.setText(majorValue+"");
			if(majorValue<majorMax && majorValue>majorMin){
				mMajorStatusTV.setText(R.string.normal);
				mMajorStatusTV.setTextColor(Color.BLACK);
			} else {
				mMajorStatusTV.setText(R.string.exception);
				mMajorStatusTV.setTextColor(Color.RED);
			}
		}
		
		{//刷新土壤湿度相关控件
			int slaveValue = mSensorValue.getSoilHumid();
			int slaveMin = mSensorConfig.minSoilHumidity;
			int slaveMax = mSensorConfig.maxSoilHumidity;
			mSlaveValueTV.setText(slaveValue+"");
			if(slaveValue<slaveMax && slaveValue>slaveMin){
				mSlaveStatusTV.setText(R.string.normal);
				mSlaveStatusTV.setTextColor(Color.BLACK);
			} else {
				mSlaveStatusTV.setText(R.string.exception);
				mSlaveStatusTV.setTextColor(Color.RED);
			}
		}
	}

	//向服务器端发送设置土壤温湿度阀值的请求
	@Override
	protected boolean onPostSet(int majorMin, int majorMax, int slaveMin,int slaveMax) {
		mRequest.resetRequest();
		mRequest.setSoil(majorMin, majorMax, slaveMin, slaveMax);
		startRequest(mRequest);
		return true;
	}
}
